package com.cby.jetpack.sample.ext

import androidx.activity.ComponentActivity
import androidx.databinding.DataBindingUtil
import androidx.viewbinding.ViewBinding

/**
 * @description: DataBindingExt
 *
 * @author ChenBaoyang
 * @date 8/9/21 16:29
 */

/**
 * 扩展函数：dataBinding 的创建和绑定
 * @param layoutId Int
 * @return VB
 */
inline fun <reified VB: ViewBinding> ComponentActivity.dataBinding(layoutId: Int) = lazy {
    dataInflater<VB>(this, layoutId)
}

/**
 * dataBinding 的创建，独立出来
 * @param activity ComponentActivity
 * @param layoutId Int
 * @return VB
 */
inline fun <reified VB: ViewBinding> dataInflater(activity: ComponentActivity, layoutId: Int) : VB {
    return DataBindingUtil.setContentView(activity, layoutId) as VB
}